package com.bridge.bridge_wd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bridge.bridge_wd.R;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @ClassName QianBaoAdapter
 * @Description TODO消息
 * @Author xushufeng
 * @CreateDate 2021/4/11 0011 20:02
 * @Version 1.0
 * @UpdateDate 2021/4/11 0011 20:02
 * @UpdateRemark 更新说明
 */
public class QianBaoAdapter extends RecyclerView.Adapter<QianBaoAdapter.BabyGoodsVH> {

    private Context mContext;
    private List<String> datas;
    private ItemClickListener mItemClickListener;

    public QianBaoAdapter(Context mContext, List<String> datas) {
        this.mContext = mContext;
        this.datas = datas;
    }

    @Override
    public BabyGoodsVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new BabyGoodsVH(LayoutInflater.from(mContext).inflate(R.layout.item_mingxi, viewGroup, false));
    }


    @Override
    public void onBindViewHolder(@NonNull BabyGoodsVH babyGoodsVH, int i) {

        babyGoodsVH.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (mItemClickListener != null) {
                    mItemClickListener.onItemClick(v, i);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public void addAll(List<String> data) {
        datas.addAll(data);
        notifyDataSetChanged();
    }

    public void clearAll() {
        datas.clear();
        notifyDataSetChanged();
    }

    public interface ItemClickListener {
        void onItemClick(View view, int i);
    }

    public void setOnItemClickListener(ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;
    }

    static class BabyGoodsVH extends RecyclerView.ViewHolder {

        TextView tv_money_laiyuan;
        TextView tv_money_time;
        TextView tv_money_number;

        public BabyGoodsVH(@NonNull View itemView) {
            super(itemView);
            tv_money_laiyuan = itemView.findViewById(R.id.tv_money_laiyuan);
            tv_money_time = itemView.findViewById(R.id.tv_money_time);
            tv_money_number = itemView.findViewById(R.id.tv_money_number);
        }
    }
}
